package com.norman.sorry.core.tiles;

import com.norman.sorry.core.pieces.IPiece;

/**
 * A helper class for creating a concrete version of a tile.
 * 
 * @author Brian Norman
 * @version 0.0.1 beta
 * @since 0.0.1 beta
 */
public abstract class AbstractTile implements ITile {

   /**
    * Whether this tile contains a game piece.
    */
   protected IPiece  piece;

   /**
    * Whether this tile is a starting tile.
    */
   protected boolean start;

   /**
    * Whether this tile is part of a safe zone.
    */
   protected boolean safe;

   /**
    * Whether this tile is a home tile.
    */
   protected boolean home;

   /**
    * Creates a new tile with the given properties.
    * 
    * @param start
    *           whether this tile is a starting tile.
    * @param safe
    *           whether this tile is part of a safe zone.
    * @param home
    *           whether this tile is a home tile.
    */
   public AbstractTile(boolean start, boolean safe, boolean home) {
      this.piece = null;
      this.start = start;
      this.safe = safe;
      this.home = home;
   }

   /**
    * {@inheritDoc}
    * 
    * @see com.norman.sorry.core.tiles.ITile#setPiece(IPiece)
    */
   @Override
   public IPiece setPiece(IPiece piece) {
      IPiece old = this.piece;
      this.piece = piece;
      return old;
   }

   /**
    * {@inheritDoc}
    * 
    * @see com.norman.sorry.core.tiles.ITile#getPiece()
    */
   @Override
   public IPiece getPiece() {
      return piece;
   }

   /**
    * {@inheritDoc}
    * 
    * @see com.norman.sorry.core.tiles.ITile#containsPiece()
    */
   @Override
   public boolean containsPiece() {
      return piece != null;
   }

   /**
    * {@inheritDoc}
    * 
    * @see com.norman.sorry.core.tiles.ITile#isStart()
    */
   @Override
   public boolean isStart() {
      return start;
   }

   /**
    * {@inheritDoc}
    * 
    * @see com.norman.sorry.core.tiles.ITile#isSafe()
    */
   @Override
   public boolean isSafe() {
      return safe;
   }

   /**
    * {@inheritDoc}
    * 
    * @see com.norman.sorry.core.tiles.ITile#isHome()
    */
   @Override
   public boolean isHome() {
      return home;
   }

}
